package com.haoma.controller;

import com.haoma.annotation.RequestCount;
import com.haoma.entity.PhotoCategory;
import com.haoma.result.Result;
import com.haoma.service.PhotoCategoryService;
import com.haoma.service.PhotoService;
import com.haoma.vo.PhotoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description: 相册相关接口
 */
@RestController
@RequestMapping("/web/photo")
@CrossOrigin

public class PhotoController {

    @Autowired
    private PhotoCategoryService photoCategoryService;

    @Autowired
    private PhotoService photoService;

    /**
     * 获取所有的相册分类
     *
     * @return
     */
    @RequestCount
    @GetMapping("/category")
    public Result getCategory() {
        List<PhotoCategory> photoCategoryList = photoCategoryService.getCategory();
        return Result.success(photoCategoryList);
    }

    /**
     * 根据分类id获取分类下的照片
     * 遇到日期bug如果被隐藏了会出现日期空状态
     *
     * @param id
     * @return
     */
    @RequestCount
    @GetMapping("/photo/{id}")
    public Result getPhotoById(@PathVariable Integer id) {
        // 获取相册图片
        List<PhotoVo> photoList = photoService.getPhotoById(id);
        return Result.success(photoList);
    }


}
